/*
 * TermOccurrenceSequentialFile.cpp
 *
 *  Created on: Nov 27, 2012
 *      Author: m
 */

#include "TermOccurrenceSequentialFile.h"

namespace physical
{

TermOccurrenceSequentialFile::TermOccurrenceSequentialFile() :
        m_file( new FixedSizeBlockSequentialFile< TERM_OCURRENCE_SIZE > ),
        m_serializer( new FixedSizeRecordSerializer< TermOccurrence > )
{
}

TermOccurrenceSequentialFile::TermOccurrenceSequentialFile( const char* filename,
        openmode mode ) :
            m_file( new FixedSizeBlockSequentialFile< TERM_OCURRENCE_SIZE >( filename, mode ) ),
            m_serializer( new FixedSizeRecordSerializer< TermOccurrence > )
{
}

TermOccurrenceSequentialFile::~TermOccurrenceSequentialFile()
{
    m_file->close();
}

TermOccurrence TermOccurrenceSequentialFile::get()
{
    byte buffer[TERM_OCURRENCE_SIZE];
    TermOccurrence term;

    m_file->get( buffer );

    m_serializer->deserialize( buffer, term );

    return term;
}

void TermOccurrenceSequentialFile::put( const TermOccurrence& term )
{
    byte buffer[TERM_OCURRENCE_SIZE];

    m_serializer->serialize( term, buffer );

    m_file->put( buffer );
}

bool TermOccurrenceSequentialFile::hasNext()
{
    return m_file->hasNext();
}

void TermOccurrenceSequentialFile::open( const char* filename, openmode mode )
{
    m_file->open( filename, mode );
}

void TermOccurrenceSequentialFile::close()
{
    m_file->close();
}

} /* namespace physical */
